<?php include $this->admin_tpl('meta');?>
<title>添加模型 - YzmCMS内容管理系统</title>
<style>
.exp{margin:0px 0px 0px 125px;color:#555;font-size:12px;}
.exp span{color:#056ef4}
</style>
</head>
<body>
<article class="page-container">
<div class="formdoby_normal"> 
	<form method="post" onsubmit="return dosub(this)">
		<ul>
			 <li class="yzm-explain-box"><label><span class="c-red">*</span>模型名称：</label>
			 	<input type="text" class="input" name="name" placeholder="如：商品模型" value="">
			 	<span class="yzm-explain">给新模型起一个名称，<br>例如：商品模型</span>
			 </li>
			 <li class="yzm-explain-box"><label><span class="c-red">*</span>模型表名：</label>
			 	<input type="text" class="input" value="" placeholder="如：shop" name="tablename" onblur="check_table(this)">
			 	<span class="yzm-explain">模型表名只能由英文字母、数字<br>和下划线组成，例如：shop</span>
			 </li>	
			 <li class="yzm-explain-box"><label><span class="c-red">*</span>模型别名：</label>
			 	<input type="text" class="input" name="alias" placeholder="如：shop" value="">
			 	<span class="yzm-explain">模型别名与模型表名规则相同，<br>区别在于模型别名可重复</span>
			 	<p class="exp" style="color:red;margin-top:3px"><i class="yzm-iconfont yzm-iconshuoming"></i> 模型别名与栏目模板关连：</p>
			 	<p class="exp">频道页模板规则是：<span>category_模型别名.html</span> 或 <span>category_模型别名_*.html</span></p>
			 	<p class="exp">列表页模板规则是：<span>list_模型别名.html</span> 或 <span>list_模型别名_*.html</span></p>
			 	<p class="exp">内容页模板规则是：<span>show_模型别名.html</span> 或 <span>show_模型别名_*.html</span></p>
			 </li>
			 <li><label>模型简介：</label>
			 	<span class="span_input"><textarea name="description" class="textarea" style="width:70%"></textarea></span>
			 </li>	
			 <li><label>默认模型：</label>
			 <span class="span_input yzm-explain-box">
			 	<label class="label_radio"><input name="isdefault" type="radio" value="1"> 是</label>
			 	<label class="label_radio"><input name="isdefault" type="radio" value="0" checked> 否</label>
			 	<span class="yzm-explain">设为默认模型后，内容管理默认展示该模型下的数据</span>
			 </span>
			 </li>				 
		</ul>
		<div class="footer_btn">
			<input type="hidden" name="dosubmit" value="1">
			<input class="btn btn-primary radius" type="submit" value="提 交">
			<input class="btn btn-default radius" type="button" value="取 消" onclick="yzmcms_close()">	
		</div>
	</form>
</div>
</article>
<?php include $this->admin_tpl('footer');?>

<script type="text/javascript">
	function check_table(obj){
		var reg = /^[a-zA-Z]{1}([a-zA-Z0-9]|[_]){0,19}$/;	
		if(obj.value.length<1 || obj.value.length>20){
			layer.msg('模型表名长度必须为1-20位！', {icon:2});
			return false;
		}
		if(!reg.test(obj.value)){
			layer.msg('模型表名必须为英文、数字或下划线！', {icon:2});
			return false;
		}
		$("input[name='alias']").val(obj.value);
	}
	function dosub(obj){
		var reg = /^[a-zA-Z]{1}([a-zA-Z0-9]|[_]){0,19}$/;	
		if(obj.name.value==''){
			layer.msg('模型名称不能为空！', {icon:2});
			return false;
		}
		if(obj.tablename.value.length<1 || obj.tablename.value.length>20){
			layer.msg('模型表名长度必须为1-20位！', {icon:2});
			return false;
		}
		if(!reg.test(obj.tablename.value)){
			layer.msg('模型表名必须为英文、数字或下划线！', {icon:2});
			return false;
		}
		if(obj.alias.value.length<1 || obj.alias.value.length>20){
			layer.msg('模型别名长度必须为1-20位！', {icon:2});
			return false;
		}
		if(!reg.test(obj.alias.value)){
			layer.msg('模型别名必须为英文、数字或下划线！', {icon:2});
			return false;
		}
        $.ajax({
            type: 'POST',
            url: '<?php echo U('add');?>', 
            data: $(obj).serialize(),
		    dataType: "json", 
            success: function (msg) {
				if(msg.status == 1){
					layer.msg(msg.message, {icon:1, time:800}, function(){
						parent.location.reload();
					});
			    }else{
					layer.msg(msg.message, {icon:2});
				}
            }
        })		 
		return false;			 
	}
</script> 

</body>
</html>